### Persist service state across runs

The following Dagger Function uses a cache volume to persist a Redis service's data across Dagger Function runs.

<Tabs groupId="language" queryString="sdk">
<TabItem value="go" label="Go">

```go file=../../../extending/modules/snippets/services/persist-service-state/go/main.go
```

</TabItem>
<TabItem value="python" label="Python">

```python file=../../../extending/modules/snippets/services/persist-service-state/python/main.py
```

</TabItem>
<TabItem value="typescript" label="TypeScript">

```typescript file=../../../extending/modules/snippets/services/persist-service-state/typescript/index.ts
```

</TabItem>
</Tabs>

#### Example

- Save data to a Redis service which uses a cache volume to persist a key named `foo` with value `123:

    <Tabs groupId="shell">
    <TabItem value="System shell">
    ```shell
    dagger -c 'set foo 123'
    ```
    </TabItem>
    <TabItem value="Dagger Shell">
    ```shell title="First type 'dagger' for interactive mode."
    set foo 123
    ```
    </TabItem>
    <TabItem value="Dagger CLI">
    ```shell
    dagger call set --key=foo --value=123
    ```
    </TabItem>
    </Tabs>

- Retrieve the value of the key `foo` after recreating the service state from the cache volume:

    <Tabs groupId="shell">
    <TabItem value="System shell">
    ```shell
    dagger -c 'get foo'
    ```
    </TabItem>
    <TabItem value="Dagger Shell">
    ```shell title="First type 'dagger' for interactive mode."
    get foo
    ```
    </TabItem>
    <TabItem value="Dagger CLI">
    ```shell
    dagger call get --key=foo
    ```
    </TabItem>
    </Tabs>
